
#include "svdpi.h"
#include "common.h"
#include <queue>
#include <vector>
#include <string>
typedef std::queue<long long> FIFO;
static std::vector<FIFO *> fifos;
static std::vector<std::string> fifo_names;
static int fifo_id = 0;
#ifdef __cplusplus
extern "C"
{
#endif

    void fifo_pop(int id, long long value)
    {
        if (id == 0)
            return;
        auto fifo = fifos[id - 1];
        if (value != fifo->front())
        {
            LOG("FIFO[%d] %s pop 0x%llx != ref 0x%llx error at %lu", fifo_id, fifo_names[id - 1].c_str(), value, fifo->front(), Verilated::time());
        }
        fifo->pop();
        return;
    }
    void fifo_push(int id, long long value)
    {
        if (id == 0)
            return;
        auto fifo = fifos[id - 1];
        fifo->push(value);
    }
    int fifo_create(int id, const char *name)
    {
        if (id == 0)
        {
            fifos.push_back(new FIFO);
            fifo_names.push_back(std::string(name));
            fifo_id++;
            LOG("FIFO[%d] %s created", fifo_id, name);
            return fifo_id;
        }
        else
        {
            auto fifo = fifos[id - 1];
            while (!fifo->empty())
            {
                fifo->pop();
            }
            return id;
        }
    }

#ifdef __cplusplus
}
#endif